package com.chenchao.thread;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/17 20:30
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.javathread.Test14.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 性能优先级
 */
public class Test14 implements Runnable{
    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getName()
                +"的优先级"+Thread.currentThread().getPriority());
        Thread thread1 = new Thread(new Test14(), "线程1");
        Thread thread2 = new Thread(new Test14(), "线程2");
        Thread thread3 = new Thread(new Test14(), "线程3");
        Thread thread4 = new Thread(new Test14(), "线程4");
        //线程优先级范围[1,10]
        //高优先级只是有更大的概率被执行
        thread1.setPriority(1);
        thread2.setPriority(10);
        thread3.setPriority(4);
        thread4.setPriority(9);
        thread1.start();
        thread2.start();
        thread3.start();
        thread4.start();
    }

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()
                    +"的优先级"+Thread.currentThread().getPriority());
        }
    }
}
